//
//  CommonTableViewCell.m
//  LotteryProject
//
//  Created by 阳光 on 17/7/9.
//  Copyright © 2017年 阳光. All rights reserved.
//

#import "CommonTableViewCell.h"

@implementation CommonTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        // ➡️Cell类型
        self.accessoryType=UITableViewCellAccessoryNone;

        self.arrowIcon.hidden=NO;

        self.nameLabel.font=FontNumber(18);

        self.detailLabel.font=FontNumber(16);

        self.backgroundColor=WhiteColor;
    }
    return self;
}

-(UIImageView *)imageUrl
{
    if (!_imageUrl) {
        _imageUrl=[UIImageView new];
        [self.contentView addSubview:self.imageUrl];
        [_imageUrl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kmargin*2);
            make.size.mas_equalTo(CGSizeMake(kmargin*5,kmargin*5));
            make.centerY.mas_equalTo(0);
        }];
    }
    return _imageUrl;
}


// nameLabel
- (UILabel *)nameLabel
{

    if (!_nameLabel) {
        _nameLabel=[self getLabelWithText:@"名字" font:FontNumber(18) textColor:DarkGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.contentView addSubview:_nameLabel];
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.imageUrl.mas_right).offset(kmargin*3/2);
            make.top.mas_equalTo(self.imageUrl.mas_top);
        }];
    }
    return _nameLabel;
}

// detailLabel
- (UILabel *)detailLabel
{
    if (!_detailLabel) {
        _detailLabel=[self getLabelWithText:@"详情" font:FontNumber(16) textColor:LightGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByTruncatingTail numberOfLines:1];
        [self.contentView addSubview:_detailLabel];
        [_detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(kmargin);
            make.bottom.mas_equalTo(self.imageUrl.mas_bottom);
            make.left.mas_equalTo(self.nameLabel.mas_left);
            make.right.mas_equalTo(self.arrowIcon.mas_left).offset(-kmargin);
        }];
    }
    return _detailLabel;
}

// arrowIcon
-(UIImageView *)arrowIcon
{
    if (!_arrowIcon) {
        _arrowIcon=[UIImageView new];
        [self.contentView addSubview:_arrowIcon];
        _arrowIcon.image=[UIImage imageNamed:@"next_arrow"];
        [_arrowIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-kmargin*2);
            make.centerY.mas_equalTo(self);
            make.size.mas_equalTo(CGSizeMake(kmargin,kmargin*2));
        }];
    }
    return _arrowIcon;
}

@end
